package com.qf.java2105.huangchuang.hotel.dao.impl;

import com.qf.java2105.huangchuang.hotel.dao.IUserDao;
import com.qf.java2105.huangchuang.hotel.pojo.User;
import com.qf.java2105.huangchuang.hotel.utils.JdbcUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * 用户持久层实现
 * @author hcvg
 * @version v1.0
 * @date 2021/09/15
 **/
public class UserDaoImpl implements IUserDao {
    private QueryRunner queryRunner = null;
    @Override
    public User login(String userName) throws SQLException {
        queryRunner = new QueryRunner(JdbcUtil.getDataSource());
        String sql = "SELECT\n" +
                "  user_id userId,\n" +
                "  username,\n" +
                "  password,\n" +
                "  nick_name nickName,\n" +
                "  is_admin isAdmin,\n" +
                "  phone,\n" +
                "  gender,\n" +
                "  user_status userStatus,\n" +
                "  user_create_time userCreateTime,\n" +
                "  user_update_time userUpdateTime,\n" +
                "  is_delete isDelete,\n" +
                "  is_member isMember,\n" +
                "  balance\n" +
                "FROM\n" +
                "  t_user\n" +
                "WHERE username = ?";
        return queryRunner.query(sql, new BeanHandler<>(User.class), userName);
    }
}
